開始動手前,我列了一下手邊的選擇:
結果在某個討論串看到有人說:「我用 VitePress 做產品頁」。咦?文檔工具做產品頁?這引起了我的好奇。
# 使用 npm
npm add -D vitepress
# 初始化(選擇最小化設定)
npx vitepress init
跑完 init 會問你一些問題,我都選最簡單的選項,因為大部分文檔功能用不到。
預設的首頁其實就很像產品頁了,稍微改一下 index.md
:
可以請 AI 協助產生~
---
layout: home
hero:
name: "超級待辦事項"
text: "讓你不再忘記任何事"
tagline: "簡單、快速、永遠免費的待辦事項管理工具"
image:
src: /hero.png
alt: Product Screenshot
actions:
- theme: brand
text: 立即開始
link: /get-started
- theme: alt
text: 查看功能
link: /features
features:
- icon: 🚀
title: 極速同步
details: 所有裝置即時同步,永遠不會遺失資料
- icon: 🎨
title: 美觀介面
details: 精心設計的使用介面,讓管理待辦事項成為享受
- icon: 🔒
title: 隱私優先
details: 你的資料只屬於你,我們不會查看或分享
---
跑 npm run docs:dev
看一下,哇,這不就是個產品頁嗎!
// .vitepress/config.js
export default {
title: '超級待辦事項',
description: '讓你不再忘記任何事',
themeConfig: {
// 關掉側邊欄
sidebar: false,
// 自訂導航
nav: [
{ text: '功能', link: '/features' },
{ text: '定價', link: '/pricing' },
{ text: '部落格', link: '/blog/' },
{ text: '登入', link: 'https://app.example.com' }
],
// 改掉 footer
footer: {
message: '超級待辦事項',
copyright: '隱私權政策 | 服務條款'
}
}
}
最酷的是可以在 Markdown 中直接用 Vue 元件!建立 .vitepress/components/PricingTable.vue
:
<template>
<div class="pricing-container">
<div class="price-card" v-for="plan in plans">
<h3>{{ [plan.name](http://plan.name) }}</h3>
<div class="price">{{ plan.price }}</div>
<ul>
<li v-for="feature in plan.features">{{ feature }}</li>
</ul>
<button>{{ plan.cta }}</button>
</div>
</div>
</template>
<script setup>
const plans = [
{
name: '免費版',
price: '$0',
features: ['無限待辦事項', '基本同步', 'Web 版本'],
cta: '開始使用'
},
// ... 其他方案
]
</script>
然後在 pricing.md
中使用:
# 選擇適合你的方案
<PricingTable />
// .vitepress/config.js 產品頁常用設定
export default {
// SEO 相關
head: [
['meta', { property: 'og:title', content: '超級待辦事項' }],
['meta', { property: 'og:description', content: '讓你不再忘記任何事' }],
['link', { rel: 'icon', href: '/favicon.ico' }]
],
// 移除 .html 後綴
cleanUrls: true,
// 自訂主題色
themeConfig: {
colorMode: 'dark', // 預設深色模式很潮
}
}
遇到的問題:預設的 CSS 變數太「文檔風」,需要覆寫一堆顏色
解決方法:在 .vitepress/theme/custom.css
中覆寫:
:root {
--vp-c-brand: #646cff;
--vp-c-brand-light: #747bff;
--vp-button-brand-bg: var(--vp-c-brand);
--vp-home-hero-name-color: transparent;
}
注意事項:
技術:VitePress
分類:靜態網站生成器 / 文檔框架
難度:⭐⭐☆☆☆
實用度:⭐⭐⭐⭐☆
一句話:把文檔框架拿來做產品頁,意外的合適
關鍵指令:npx vitepress init
適用情境:需要快速建立產品頁、部落格、文檔網站
花了一小時把 VitePress 改造成產品頁,比預期順利很多。它讓我想到一個道理:工具的價值不在於它被設計來做什麼,而在於它能幫你解決什麼問題。
VitePress 雖然定位是文檔工具,但它的「靜態網站生成」本質,加上 Vue 的靈活性,反而讓它成為快速建立產品頁的好選擇。特別是當你:
下次要做產品頁,我會直接從 VitePress 開始,不用再繞一圈評估各種框架了。